home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / tex / mf / rexx / maketexfont.rexx < prev    next >
OS/2 REXX Batch file  |  1994-06-01  |  14KB  |  501 lines

  1. /*
  2. ** AREXX $VER: MakeTeXFont 1.05
  3. **
  4. ** Send new features and bug reports to 
  5. **
  6. ** Martin Bokaemper
  7. ** Reuthstr. 12
  8. ** 91099 Poxdorf
  9. ** Germany
  10. **
  11. ** Email: mnbokaem@cip.e-technik.uni-erlangen.de (Internet)
  12. **        mab@ame.zer (Zerberus)
  13. **
  14. ** Ulrich Wisser
  15. ** Heerstr. 125
  16. ** 53111 Bonn
  17. **
  18. ** HISTORY:
  19. **
  20. ** 0.80: My 'works-fine-for-me' version modified by Georg Hessmann 13.04.91
  21. **       + Variables for all directories and filenames
  22. **       + ^C and ^D detection 
  23. **       + support for a 'modefile' containing site-specific information
  24. **       + searches for standard magsteps 
  25. **       + support for different format-files
  26. **
  27. ** 0.81: + take new Parameters 'drivertype' and 'pkfilename' 
  28. **       Georg Hessmann 17.04.91
  29. **
  30. ** 0.82: + History 
  31. **       + a lot of small improvements and bugfixes
  32. **       + looking for PK-directory for each device 
  33. **       + checking if the font already exists
  34. **       Martin Bokaemper 21.04.91
  35. **
  36. ** 0.84: + add new parameter 'pkdir' (new since driver version V1.10)
  37. **       Georg Hessmann 09.06.91
  38. **
  39. ** 0.85: + fixed a pkdir/pkfilename mixing bug
  40. **       + slight modifications, now works with old driver versions
  41. **       + changed exit codes
  42. **       + always calls uses plain.base (absolutely no gain in using cmbase)
  43. **       J\"org H\"ohle 24.6.91, 01.08.91
  44. **
  45. ** 0.86: + fixed makedir(pkname) bug
  46. **       J\"org H\"ohle 06.08.91
  47. **
  48. ** 0.90: + add makedir(pkdir)
  49. **       + delete localfont entry in 'modes' file
  50. **       Georg Hessmann 28.08.91
  51. **
  52. ** 1.00: + only one logfile entry per call
  53. **       + ERROR: now reports interpreted sourceline
  54. **       + fonts can be copied to mf:<mode> for font-caching
  55. **       + magstep calculation improved.  now same as in ShowDVI/DVIPrint
  56. **       + MISSING: \scrollmode correctly inserted
  57. **       Ulrich Wisser 25.08.92
  58. **
  59. ** 1.01: + bumped revision number because of partial integration of
  60. **       + versions 0.91 and 1.0 and some personal modifications.
  61. **       Andreas Scherer 31.10.93
  62. **
  63. ** 1.02: + negative magnification factors and dpi values installed.
  64. **       Andreas Scherer 18.01.94
  65. **
  66. ** 1.03: + support for dvips 5.523 resulted in a modified analysis of
  67. **       + the `modes' file.  PKDIR now *always* comes as an argument
  68. **       + of this script (as implemented by Ulrich Wisser).
  69. **       Andreas Scherer 19.01.94
  70. **
  71. ** 1.04: + METAFONT 2.71 returns 0, 5, 10, and 20, so a different ERROR
  72. **       + handling is necessary (and possible).
  73. **       Andreas Scherer 2.5.94
  74. **
  75. ** 1.05: + add MyGetEnv at the end of the file
  76. **       + add ENV:MFLOGDIR to change the logging directory
  77. **         Change default to T:MFlog.
  78. **       + add ENV:MFTMPDIR to change the working directory
  79. **         The directory, where virmf will be started. MF: isn't
  80. **         a good choice, because this can be on a CD-ROM (ro).
  81. **         Change default woring directory from MF: to T:
  82. **       + use the PKDIR from the argument, not from the TeX:config/modes
  83. **         file. This dir variable is renamed to MODEPKDIR but is noop.
  84. **       Georg Heßmann 13.05.94
  85. */
  86.  
  87. Signal On BREAK_C
  88. Signal On BREAK_D
  89.  
  90. /*
  91. ** Files / Directories
  92. */
  93.  
  94. LOGDIR = Word(MyGetEnv("MFLOGDIR"),1)    /* not to MF: .. it could be on CD-ROM */
  95. If "" = LOGDIR Then
  96.   LOGDIR       = "T:MFlog"              /* directory of the logfiles           */
  97.                                         /* without trailing slash!             */
  98.  
  99. WORKDIR = Word(MyGetEnv("MFTMPDIR"),1)    /* working directory                   */
  100. If "" = WORKDIR Then            /* not MF: .. it could be on CD-ROM    */
  101.   WORKDIR       = "T:"
  102.  
  103.  
  104. LOGNAME      = LOGDIR"/MakeTeXFont.log" /* logfile                      */
  105. MODEFILENAME = "MF:config/modes"        /* description of the modes     */
  106. TEXTFM       = "TeX:fonts/"             /* TeX tfm-files directory      */
  107. VIRMF        = "MF:bin/VirMF"
  108. GFTOPK       = "MF:bin/GFtoPK"
  109. FONTFILENAME = "TeX:config/fontvols"
  110.  
  111. /*
  112. ** Bases. Put in others, if you like.
  113. */
  114. NORMALBASE = "plain"
  115. DXBASE     = "dxbase"            /* base for dc-fonts        */
  116. CMBASE     = "cmbase"            /* base for cm-fonts        */
  117.  
  118. /*
  119. ** Arguments
  120. */
  121. Parse Arg FNTNAME DPI HBASEDPI VBASEDPI DRIVERTYPE PKFILENAME PKDIR .
  122.  
  123. Say "Making font "FNTNAME" at "DPI" dpi and base ("HBASEDPI","VBASEDPI")"
  124.  
  125. If ~Show('Libraries','rexxsupport.library') Then Do
  126.   If ~AddLib('rexxsupport.library',0,-30) Then Do
  127.      Say "No RexxSupport.library ... No Metafont!"
  128.      Exit 5
  129.   End
  130. End
  131.  
  132. DUMMY = Time("Reset")
  133.  
  134. If ~Exists(LOGDIR) Then Do
  135.   Address COMMAND 'MakeDir 'LOGDIR
  136.   If ~Exists(LOGDIR) Then Do
  137.     Call Log("Could not create logdir="LOGDIR)
  138.     Exit 5
  139.   End
  140.   Say "logfile-directory ("LOGDIR"/) did not exist. It was created."
  141. End
  142.  
  143. If ~Exists(LOGNAME) Then Do
  144.   Address COMMAND 'echo >'||LOGNAME
  145.   If ~Exists(LOGNAME) Then Do
  146.     Call Log("Could not create logfile="LOGDIR"/"LOGNAME)
  147.     Exit 5
  148.   End
  149.   Say "logfile did not exist. It was created."
  150. End
  151.  
  152. FNTNAME    = Translate(FNTNAME,XRange('a','z'),XRange('A','Z')) /* lower */
  153. DPI        = Strip(DPI)
  154. HBASEDPI   = Strip(HBASEDPI)
  155. VBASEDPI   = Strip(VBASEDPI)
  156. DRIVERTYPE = Translate(DRIVERTYPE,XRange('a','z'),XRange('A','Z')) /* lower */
  157. PKFILENAME = Translate(PKFILENAME,XRange('a','z'),XRange('A','Z')) /* lower */
  158. PKDIR      = Translate(PKDIR,XRange('a','z'),XRange('A','Z')) /* lower */
  159.  
  160. /*
  161. ** Changed 19.07.92 by Ulrich Wisser
  162. ** Needed to calculate correct DPI sizes
  163. */
  164. Numeric DIGITS 12
  165.  
  166. /*
  167. ** What magstep should the font have?
  168. */
  169. MAG = DPI/HBASEDPI
  170.  
  171. /*
  172. ** MAGMULT.NUM.I set to correct values!
  173. ** 21.07.92 by Ulrich Wisser
  174. ** Needed to calculate correct DPI values.
  175. **
  176. ** Some more values for magstep(-0.5)..magstep(-4) included.
  177. ** 18.01.94 by Andreas Scherer.
  178. */
  179. MAGMULT.0      = 23            /* number of saved MagSteps */
  180.  
  181. MAGMULT.NUM.1  = 1.0           /* MagStep(0)    */
  182. MAGMULT.STR.1  = "0"
  183. MAGMULT.NUM.2  = 1.09544511501 /* MagStep(0.5)  */
  184. MAGMULT.STR.2  = "0.5"
  185. MAGMULT.NUM.3  = 1.2           /* MagStep(1)    */
  186. MAGMULT.STR.3  = "1"
  187. MAGMULT.NUM.4  = 1.31453413801 /* MagStep(1.5)  */
  188. MAGMULT.STR.4  = "1.5"
  189. MAGMULT.NUM.5  = 1.44          /* MagStep(2)    */
  190. MAGMULT.STR.5  = "2"
  191. MAGMULT.NUM.6  = 1.57744096561 /* MagStep(2.5)  */
  192. MAGMULT.STR.6  = "2.5"
  193. MAGMULT.NUM.7  = 1.728         /* MagStep(3)    */
  194. MAGMULT.STR.7  = "3"
  195. MAGMULT.NUM.8  = 2.0736        /* MagStep(4)    */
  196. MAGMULT.STR.8  = "4"
  197. MAGMULT.NUM.9  = 2.48832       /* MagStep(5)    */
  198. MAGMULT.STR.9  = "5"
  199. MAGMULT.NUM.10 = 2.985984      /* MagStep(6)    */
  200. MAGMULT.STR.10 = "6"
  201. MAGMULT.NUM.11 = 3.5831808     /* MagStep(7)    */
  202. MAGMULT.STR.11 = "7"
  203. MAGMULT.NUM.12 = 4.29981696    /* MagStep(8)    */
  204. MAGMULT.STR.12 = "8"
  205. MAGMULT.NUM.13 = 5.159780352   /* MagStep(9)    */
  206. MAGMULT.STR.13 = "9"
  207. MAGMULT.NUM.14 = 0.91287092917 /* magstep(-0.5) */
  208. MAGMULT.STR.14 = "-0.5"
  209. MAGMULT.NUM.15 = 0.83333333333 /* magstep(-1)   */
  210. MAGMULT.STR.15 = "-1"
  211. MAGMULT.NUM.16 = 0.76072577431 /* magstep(-1.5) */
  212. MAGMULT.STR.16 = "-1.5"
  213. MAGMULT.NUM.17 = 0.69444444444 /* magstep(-2)   */
  214. MAGMULT.STR.17 = "-2"
  215. MAGMULT.NUM.18 = 0.63393814526 /* magstep(-2.5) */
  216. MAGMULT.STR.18 = "-2.5"
  217. MAGMULT.NUM.19 = 0.5787037037  /* magstep(-3)   */
  218. MAGMULT.STR.19 = "-3"
  219. MAGMULT.NUM.20 = 0.52828178771 /* magstep(-3.5) */
  220. MAGMULT.STR.20 = "-3.5"
  221. MAGMULT.NUM.21 = 0.48225308641 /* magstep(-4)   */
  222. MAGMULT.STR.21 = "-4"
  223. MAGMULT.NUM.22 = 0.44023482309 /* magstep(-4.5) */
  224. MAGMULT.STR.22 = "-4.5"
  225. MAGMULT.NUM.23 = 0.40187757201 /* magstep(-5)   */
  226. MAGMULT.STR.23 = "-5"
  227.  
  228. MAGMULT.STR.DEFAULT = "???"
  229. MAGSTR              = MAGMULT.STR.DEFAULT
  230.  
  231. /*
  232. ** Changed 21.07.92 by Ulrich Wisser
  233. ** DPI rounding caused troubles sometimes, e.g., for
  234. ** magstep2 with ShowDVI 44x44
  235. */
  236. Do I = 1 To MAGMULT.0
  237.   MAGDPI = (MAGMULT.NUM.I * HBASEDPI) + 0.5
  238.   If Pos('.',MAGDPI) > 0 Then
  239.     MAGDPI = Left(MAGDPI,Pos('.',MAGDPI)-1)
  240.   If MAGDPI = DPI Then Do
  241.     MAG    = MAGMULT.NUM.I
  242.     MAGSTR = MAGMULT.STR.I
  243.     Leave I
  244.   End
  245. End
  246.  
  247. If MAGSTR ~= MAGMULT.STR.DEFAULT Then MAG = 'magstep('magstr')'
  248.  
  249. /*
  250. ** Modes ... search the correct mode in the file MODEFILENAME (see above).
  251. */
  252. If ~Open('MODEFILE',MODEFILENAME,'READ') Then Do
  253.   Call Log("Can't find file "MODEFILENAME"!")
  254.   Exit 5
  255. End
  256.  
  257. Do Until(XRES==HBASEDPI & YRES==VBASEDPI) | EOF('MODEFILE')
  258.   LINE = ReadLn('MODEFILE')
  259.   LINE = Strip(Translate(LINE, ' ', '    '))
  260.   MODE = Word(LINE,1)
  261.   XRES = Word(LINE,2)
  262.   YRES = Word(LINE,3)
  263.   MODEPKDIR = Word(LINE,4)    /* variable not yet used */
  264. End
  265.  
  266. If ~Close('MODEFILE') Then
  267.   Call Log("Can't close mode-file!")
  268.  
  269. If XRES ~= HBASEDPI | YRES ~= VBASEDPI Then Do
  270.   MODE = '' /* for pretty log-entry */
  271.   Call Log("Can't find matching mode!  Make an update in your "MODEFILENAME" file.")
  272.   Exit 5
  273. End
  274.  
  275. /*
  276. ** Produce the complete name of the file.
  277. */
  278. If PKFILENAME="" Then
  279.   PKNAME = PKDIR||DPI'/'FNTNAME'.'DPI'pk'
  280. Else
  281.   PKNAME = PKDIR||PKFILENAME
  282.  
  283. /*
  284. ** Look if the font already is there.
  285. */
  286. If Exists(PKNAME) Then Do
  287.   Say "The font "PKNAME" already exists!"
  288.   Say "Check your driver's configuration!"
  289.   Call Log(PKNAME" already exists; check your driver's configuration!")
  290.   Exit 5
  291. End
  292.  
  293. /*
  294. ** Install the options MetaFont is called with.
  295. */
  296. FORMAT = NORMALBASE
  297.  
  298. FNTSTART = substr(FNTNAME,1,2)
  299. If "dc" = FNTSTART Then
  300.   FORMAT = DXBASE
  301. If "cm" = FNTSTART Then
  302.   FORMAT = CMBASE
  303.  
  304.  
  305.  
  306. /*
  307. ** Install the options MetaFont is called with.
  308. */
  309. If MAGSTR ~= MAGMULT.STR.DEFAULT Then
  310.   OPTIONS = "\mode:="MODE"; mag:=magstep("MAGSTR"); scrollmode; input "FNTNAME
  311. Else
  312.   OPTIONS = "\mode:="MODE"; mag:="MAG"; scrollmode; input "FNTNAME
  313.  
  314.  
  315. /*
  316. ** Set working directory (to a read-write directory, RAM: prefered :)
  317. */
  318. DUMMY = Pragma("directory",WORKDIR)    /* changed (hes) MF: on CD-ROM isn't a good working dir ;) */
  319.  
  320.  
  321.  
  322. Address COMMAND
  323.  
  324. /*
  325. ** First: Create the GF-file and the TFM-file and the LOG-file
  326. ** by calling the METAFONT progam.  If anything below fails, you
  327. ** can proceed by hand; all necessary files will be present.
  328. */
  329. Say "Calling MetaFont with format: &"FORMAT" and startup commands: "
  330. Say "'"OPTIONS"'"
  331.  
  332. VIRMF '&'FORMAT' "'OPTIONS'"'
  333.  
  334. /*
  335. ** My version of METAFONT returns codes 0, 5, 10 or 20.
  336. ** Take appropriate actions.
  337. ** Andreas Scherer 2.5.94.
  338. */
  339. ERRORCODE = RC
  340.  
  341. If 5 >= ERRORCODE Then Do
  342.   If 0 < ERRORCODE Then
  343.     Call Error
  344.   Else
  345.     Say FNTNAME" translated without errors."
  346. End; Else Do
  347.   Call Error
  348.   EDITSCRIPT = Word(MyGetEnv("MFREXXEDIT"),1)
  349.   If "" = EDITSCRIPT Then
  350.     EDITSCRIPT = 'MF:rexx/MFEdit.rexx'
  351. /* 
  352. **  (hes) Ignore error codes, this should work automatically.
  353. **  Say "Start editor for "FNTNAME" with "EDITSCRIPT"."
  354. **  'rx 'EDITSCRIPT FNTNAME'.mf' 0
  355. **  Exit 0
  356. */
  357. End
  358.  
  359. /*
  360. ** Second: Create the PK-file by calling the GFtoPK program.
  361. ** This is done in the "MF:" directory, not in the final path.
  362. */
  363. GFTOPK FNTNAME'.'DPI'gf'
  364.  
  365. /*
  366. ** Don't delete the GF-file on failure.
  367. */
  368. If Exists(FNTNAME'.'DPI'pk') Then Do
  369.   Delete FNTNAME'.'DPI'gf'
  370.   FileNote FNTNAME'.'DPI'pk' ' "mode='MODE', magstep='MAGSTR'"'
  371. End
  372.  
  373. /*
  374. ** Third: Create all needed directories and try to move the
  375. ** files appropriately.
  376. */
  377.  
  378. /*
  379. ** Don't include last '/' in PKDIR, makedir doesn't like it.
  380. */
  381. PKDIR2 = Left(PKDIR,LastPos("/",PKDIR)-1)
  382.  
  383. If ~Exists(PKDIR2) Then
  384.   If ~MakeDir(PKDIR2) Then Do
  385.     Call Log("MakeDir "PKDIR2" failed")
  386.     Exit 5
  387.   End
  388.  
  389. /*
  390. ** A '/' is required to exist in PKNAME, but don't include it
  391. ** in FULLDIR, makedir doesn't like it.
  392. */
  393. FULLDIR = Left(PKNAME,LastPos("/",PKNAME)-1)
  394.  
  395. If ~Exists(FULLDIR) Then
  396.   If ~MakeDir(FULLDIR) Then Do
  397.     Call Log("MakeDir "FULLDIR" failed")
  398.     Exit 5
  399.   End
  400.  
  401. /*
  402. ** Check the TFM-file; if it doesn't exist, move it there
  403. ** and delete it here.
  404. */
  405. If Exists(TEXTFM) & ~Exists(TEXTFM||FNTNAME'.tfm') Then Do
  406.   Copy FNTNAME'.tfm' TEXTFM clone
  407.   Protect TEXTFM||FNTNAME'.tfm' r
  408. End
  409.  
  410. Delete FNTNAME'.tfm'
  411.  
  412. /*
  413. ** The following section makes a copy of the pk-file to MF:<mode>/PKFILENAME
  414. ** This is useful if you like to copy all new font-files to disks for
  415. ** future font-caching.  See the documentation for further details.
  416. */
  417. /*
  418. If ~Exists(MODE) Then Do
  419.   If ~MakeDir(MODE) Then Do
  420.     Call Log("Makedir "MODE" failed!")
  421.   End
  422. End
  423. If ~Exists(MODE'/'DPI) Then Do
  424.   If ~MakeDir(MODE'/'DPI) Then Do
  425.     Call Log("Makedir "MODE"/"DPI" failed!")
  426.   End
  427. End
  428. If Exists(MODE) Then
  429.   Copy FNTNAME'.'DPI'pk' MODE'/'PKFILENAME
  430. */
  431.  
  432. Copy FNTNAME'.'DPI'pk' PKNAME clone
  433. Delete FNTNAME'.'DPI'pk'
  434. Protect PKNAME r
  435.  
  436. /*
  437. ** Copy/Delete instead Rename to overwrite existing logfile (e.g., from
  438. ** a failed call of MakeTeXfont). Replace by 'move' if you have ARP:
  439. ** i.e., add a line here ``copy = "move" or "mv"''.  This seems to be
  440. ** the case for Ulrich Wisser in Version 1.0, as he uses "move" here.
  441. ** I still assume that most people want to use this script with the
  442. ** original WorkBench, so double moving would cause this to crash.
  443. ** Also, copy/delete unlike move works between devices, too.
  444. */
  445. Copy FNTNAME'.log' LOGDIR'/'FNTNAME'.'DPI'log'
  446. Delete FNTNAME'.log'
  447.  
  448. ELAPSED = Time("ELAPSED")
  449. Call Log("created in "ELAPSED%3600":"Right(ELAPSED%60//60,2,'0')":"Right(ELAPSED%1//60,2,'0'))
  450.  
  451. Exit 0
  452.  
  453. /*
  454. ** Log-function
  455. */
  456. LOG: Procedure Expose LOGNAME FNTNAME MODE HBASEDPI VBASEDPI DPI MAGSTR
  457. Parse Arg MSG
  458.  
  459. MESSAGE = Date()" "Time()": "FNTNAME" for "MODE" ("HBASEDPI","VBASEDPI") with "DPI" dpi (mag="MAGSTR") "'0A'X || MSG
  460. Say MESSAGE
  461.  
  462. If ~Open(LOGFILE,LOGNAME,'Append') Then Do
  463.   Say "Can't open logfile!"
  464.   Return
  465. End
  466.  
  467. DUMMY = Writeln(LOGFILE,MESSAGE)
  468. If ~Close(LOGFILE) Then
  469.   Say "Can't close logfile!"
  470.  
  471. Return
  472.  
  473. ERROR:
  474.   Say "Translation problem, MetaFont returned "ERRORCODE"."
  475.   Call Log("Translation problem, MetaFont returned "ERRORCODE".")
  476. Return
  477.  
  478. BREAK_C:
  479. BREAK_D:
  480.   Call Log "execution aborted!"
  481.   If Exists(FNTNAME'.'DPI'gf') Then
  482.     DUMMY = Delete FNTNAME'.'DPI'gf'
  483.   If Exists(FNTNAME'.log') Then
  484.     DUMMY = Delete FNTNAME'.log'
  485.  
  486.   Exit 1
  487.  
  488. /*
  489. ** When will Arexx supply GetEnv/SetEnv ?
  490. */
  491. MyGetEnv: Procedure
  492. Parse Arg NAME
  493.  
  494. If Open(TEMPFILE,"ENV:"||NAME,'r') Then Do
  495.   GIVES = Readln(TEMPFILE)
  496.   Call Close TEMPFILE
  497. End; Else
  498.   GIVES = ""
  499.  
  500. Return GIVES
  501.